package lk.uom.theta;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lk.uom.theta.business.H1N1IncidentEAO;

/**
 * Servlet implementation class IncidentReportFormHandler
 */
import java.io.IOException;
import java.util.Date;
import javax.ejb.EJB;
import lk.uom.theta.entity.H1N1Incident;
public class IncidentReportFormHandler extends HttpServlet {

    private static final long serialVersionUID = 1L;
    
    @EJB
    private H1N1IncidentEAO incidentEAO;

    /**
     * Default constructor. 
     */
    public IncidentReportFormHandler() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        String address = request.getParameter("address");

        int month = Integer.parseInt(request.getParameter("element_7_1"));
        int day = Integer.parseInt(request.getParameter("element_7_2"));
        int year = Integer.parseInt(request.getParameter("element_7_3"));
        Date bday = new Date(year, month, day);

        String area = request.getParameter("city");

        String complaints = request.getParameter("description");

        String othersymptoms = request.getParameter("othersymptoms");
        String contacthistory = request.getParameter("contacthistory");
        String travelhostory = request.getParameter("travelhostory");
        
        H1N1Incident incident = new H1N1Incident();
        incident.setArea(area);
        incident.setComplaints(complaints);
        incident.setContactHistory(contacthistory);
        incident.setContactInformation(address);
        incident.setDateOfBirth(bday);
        incident.setGender(area);
        incident.setPatientName(name);
        incident.setTravelHistory(travelhostory);

        incidentEAO.create(incident);

    }
}
